<?php
	$_product = $this->getProduct();
	$_helper = $this->helper('catalog/output');
	$zgbHelper = Mage::helper('zgb');
	/*同牌推荐*/
	$brandId = $_product->getBrand();
	$productId = $_product->getId();
	$sameBrandProducts = Mage::getResourceModel('catalog/product_collection')
                        ->addAttributeToSelect(array('small_image','name','price'))
                        ->addAttributeToFilter('visibility', array('neq' => 1))
                        ->addAttributeToFilter('status', 1)
                        ->addAttributeToFilter('entity_id', array('neq' => $productId))
                        ->addAttributeToFilter('brand',$brandId)
                        ->setCurPage(1)
                        ->setPageSize(4);
	Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($sameBrandProducts);
	Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($sameBrandProducts);
	Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($sameBrandProducts);
?>
<div  class="row main">
	<ul class="breadcrumbs">
		<li>
			<a href="<?php echo Mage::getBaseurl() ?>" title="前往主页">主页</a>
			<span>></span>
		</li>
		<li><strong><?php echo $_product->getName(); ?></strong></li>
	</ul>


	<div class="row productDetail">
		<div class="product-imagebox">
			<!-- Image Box For Product -->
			<a id="cloudZoom" class="pro-bgimg cloud-zoom" title='Thumbnail 1'
			   rel="zoomWidth: '200',zoomHeight: '200',position: 'right',smoothMove: 3,showTitle: true,titleOpacity: 0,lensOpacity: 0,tintOpacity: 0,softFocus: false" href="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>" gallery="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>">
			   	<img title="<?php echo $_product->getName(); ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>"/></a>
			<?php if(count($this->getGalleryImages()) > 0): ?>
			<div class="pro-smimgs">
				<ul class="slides">
					<?php foreach($this->getGalleryImages() as $_image): ?>
						<li>
							<a  href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize(640); ?>" rel="useZoom: 'cloudZoom', smallImage: '<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize(640); ?>'" class="cloud-zoom-gallery" title="<?php echo $this->escapeHtml($_image->getLabel()) ?>">
								<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(74); ?>" width="56" height="56" alt="" draggable="false">
							</a>
						</li>
					<?php endforeach; ?>
				</ul>
			</div>
			<?php endif; ?>

			<div class="row li-proTip">
				<div class="col-2 left">商品编码：<?php echo $_product->getSku() ?></div>
				<div class="col-2 right">
					<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="li-collect">收藏商品</a>
				</div>
			</div>
		</div>
		<div class="product-shop">
			<div class="name">
				<h1><?php echo $_product->getName() ?></h1>
			</div>
			<?php 
	    		$proid = $_product->getId();
	        	$pro = Mage::getModel('catalog/product')->load($proid);
	    	 ?>
	    	 <?php if($pro->getPromotion()): ?>
				<div class="date">
					<h1><?php echo $pro->getPromotion();?></h1>
				</div>
			<?php endif; ?>

			<div class="row pro-info">
				<div class="price-info">
					<?php if(number_format($_product->getPrice(),2) <= number_format($_product->getFinalPrice(),2)): ?>
						<div class="chuxiao-info">
							<strong>价格</strong>
							<span>￥<i><?php echo number_format($_product->getPrice(),2) ?></i></span>
						</div>
					<?php else : ?>
						<div class="old-info">
							<strong>原价</strong>
							<span>￥<?php echo number_format($_product->getPrice(),2)?></span>
						</div>
						<div class="chuxiao-info">
							<strong>促销价</strong>
							<span>￥<i><?php echo number_format($_product->getFinalPrice(),2) ?></i></span>
						</div>
					<?php endif; ?>
					<div class="">
						<span style="color:#f2f2f2"><?php echo $_product->getSku(); ?></span>
					</div>
				</div>

				<div class="pro-erweima">
					<img src="<?php echo Mage::getBaseUrl() . 'admin_zgb/qr/render/sku/' . $_product->getSku(); ?>" width="87">
					<div class="tip">客户端扫购更便捷</div>
				</div>
			</div>
			<div class="row pro-qty" id="datactions" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
				<strong>数量</strong>
				<div class="col-2 qty-area">
					<span class="reduce">-</span>
					<div class="qty-input">
						<input type="text" name="qty" id="qty" value="1"/>
					</div>
					<span class="add">+</span>
				</div>
			</div>
			<div class="col-1">
				<button class="cart-button add-to-cart-button">加入购物车</button>
			</div>

		</div>
		<div class="product-samebrand">
			<div class="same-title">
				<span>同品牌推荐</span>
				<div class="same-title-line"></div>
			</div>
			<?php if(count($sameBrandProducts)>0): ?>
				<div style="height:500px;overflow: hidden">
					<ul class="brand-content" data-index="0">
						<?php foreach($sameBrandProducts as $product): ?>
							<li>
								<a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>">
									<img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize('150'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
								</a>
								<div class="info-box">
									<a class="name" href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>">
										<?php 
					                        $name = $_helper->productAttribute($product, $product->getName(), 'name');
					                        $encoding = mb_internal_encoding();
					                        mb_internal_encoding("UTF-8");
					                        if(mb_strlen($name) >25){
					                            echo mb_substr($name,0,25).'...';
					                        }else{
					                            echo $name;
					                        }
					                        mb_internal_encoding($encoding);
				                        ?>
									</a>
									<div class="row price-box">
										<div class="col-2 special-price">￥<?php echo $product->getFinalPrice();?></div>
									</div>
								</div>
							</li>
						<?php endforeach; ?>
					</ul>
					<div class="row brand-icon">
						<div class="col-2 prev icon-angle-up">上一页</div>
						<div class="col-2 next  icon-angle-down">下一页</div>
					</div>
				</div>
			<?php else : ?>
				<p>&nbsp;&nbsp;暂时没有同品牌商品...</p>
			<?php endif; ?>
		</div>

	</div>
	<div class="description">
		<p>商品描述:</p>
		<div class="description-content">
			<span>
				<?php echo $_helper->productAttribute($_product, nl2br($_product->getDescription()), 'description') ?>
			</span>
			<?php if($_helper->productAttribute($_product, nl2br($_product->getDescription()), 'description') !== $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description')): ?>
			<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>
			<?php endif; ?>
		</div>
	</div>
	<div class="li-tab" >
		<a class="active">猜你喜欢<span class="li-tab-caret"></span><span class="line active"></span></a>
		<a href="<?php echo Mage::getBaseUrl() . 'admin_zgb/recent/index/'?>">最近进货<span class="li-tab-caret"></span> <span class="line"></span></a>
	</div>
	<div class="product-list guess-list">
		<!-- for show other product Start -->
    	<?php 
 			$randProducts = Mage::getModel('catalog/product')
 				->getCollection();
 			Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($randProducts);
			Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($randProducts);
			Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($randProducts);
			$randProducts->getSelect()->limit(10)->order("rand()");

    	?>
		<ul class="slides">
			<?php foreach($randProducts as $_rand): ?>
			<?php $thisproduct= Mage::getModel('catalog/product')->load($_rand->getId()); ?>
			<li>
				<div class="product-wrap">
					<div class="product-image">
						<a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>">
							<img class="lazy" src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(200) ?>" style="display: inline;">
						</a>
						<?php if($zgbHelper->hasTag($thisproduct)): ?>
						<div class="product-sale-tag">
							<img src="<?php echo $zgbHelper->getSaleTagUrl($thisproduct, $this->getSkinUrl('images')); ?>" alt="">
						</div>
						<?php endif; ?>
					</div>
					<div class="product-shop">
						<h3><?php echo $thisproduct->getName() ?></h3>

						<div class="row">
							<span class="col-2 special-price">
			                    ￥&nbsp;<?php echo $thisproduct->getFinalPrice(); ?>
			                </span>
						</div>

						<div class="row fill-box" id="datactions" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$thisproduct->getId())); ?>">
							<div class="col-2 qty-area">
								<span class="reduce">-</span>
								<div class="qty-input">
									<input type="text" value="1">
								</div>
								<span class="add">+</span>
							</div>
							<div class="col-2">
								<button class="add-cart-button">加入购物车</button>
							</div>
						</div>
					</div>
				</div>
			</li>
			<?php endforeach; ?>
		</ul>
		<!-- for show other product End -->
	</div>

</div>
<script>
	$(function(){
		$(".pro-smimgs").flexslider({
			animation: "slide",
			animationLoop: true,
			itemWidth:30,
			directionNav: true,
			controlNav: false,
			pauseOnHover: true,
			prevText: "",
			nextText: "",
			minItems: 5,
			maxItems: 5
		});
		$(".product-list").flexslider({
			animation: "slide",
			animationLoop: true,
			directionNav: true,
			itemWidth:30,
			controlNav: false,
			pauseOnHover: true,
			prevText: "",
			nextText: "",
			minItems: 4,
			maxItems: 4
		});

	})
</script>

<!-- This is Rewrite Paly -->
<script type="text/javascript">
	if (!window.Mage) var Mage = {};
	Mage.Cookies = {};
	Mage.Cookies.expires  = null;
	Mage.Cookies.set = function(name, value){
     var argv = arguments;
     var argc = arguments.length;
     var expires = (argc > 2) ? argv[2] : Mage.Cookies.expires;
     var path = (argc > 3) ? argv[3] : Mage.Cookies.path;
     var domain = (argc > 4) ? argv[4] : Mage.Cookies.domain;
     var secure = (argc > 5) ? argv[5] : Mage.Cookies.secure;
     document.cookie = name + "=" + escape (value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
	};
</script>